module ActiveDirectory
  module Schema
    def self.extend_with_schema(parent_klass)
      parent_klass.schema.each do |attr_name, definition|
        if definition[1] == :public
          parent_klass.class_eval <<-EOM
            def #{attr_name}
              attributes(:#{attr_name})
            end

            def #{attr_name}=(new_value)
              @local_attributes[:#{attr_name}] = new_value
            end
          EOM

          unless definition[2].nil?
            parent_klass.class_eval <<-EOM
              alias_method :#{definition[2]}, :#{attr_name}
              alias_method :#{definition[2]}=, :#{attr_name}=
            EOM
          end
        end
      end
    end

    module Base
      def schema
        {}
      end
      
      def schema_system_attributes
        {}
      end
    end
  end
end
